package com.ajun.service;

import com.ajun.entity.Dispatch;
import com.ajun.entity.dto.OrderDto;
import com.ajun.mapper.DispatchMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 运单业务
 *
 * @author LiJun
 * @date 2021-07-15
 */
@Slf4j
@Service
public class DispatchService {

    @Resource
    private DispatchMapper dispatchMapper;

    public Boolean dispatch(OrderDto order) {
        Dispatch dispatch = new Dispatch();
        dispatch.setOrderId(order.getOrderId());
        dispatch.setUserId(order.getUserId());
        dispatch.setOrderContent(order.getOrderContent());
        dispatch.setStatus(true);
        dispatch.setCreateTime(LocalDateTime.now());
        int count = dispatchMapper.insert(dispatch);

        if (count != 1) {
            throw new RuntimeException("运单创建失败");
        }
        return true;
    }
}
